# -*- coding: utf-8 -*-
# @Time    : 2018/8/14 14:50
# @Author  : 聂家利
# @Email   : 1073438012@qq.com
# @File    : __init__.py
# @Software: PyCharm

from flask import Flask
from flask_login import LoginManager
from flask_mail import Mail

from app.models.base import db


login_manager = LoginManager()

mail = Mail()


def create_app():
    app = Flask(__name__, static_folder='static')
    app.config.from_object('app.secure')
    app.config.from_object('app.setting')
    register_blueprint(app)
    db.init_app(app)
    login_manager.init_app(app)
    login_manager.login_view = 'web.login'
    login_manager.login_message = '请先登录或者注册'
    mail.init_app(app)
    # db.create_all(app=app)
    with app.app_context():
        db.create_all()
    return app


# 4.2 5:01
def register_blueprint(app):
    from app.web.book import web
    app.register_blueprint(web)